package edu.zsl.controller;

import edu.zsl.pojo.Student;
import edu.zsl.service.AccountStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

@Controller
public class AccountStudentController {
    private final AccountStudentService accountStudentService;
    @Autowired
    public AccountStudentController(AccountStudentService accountStudentService) {
        this.accountStudentService = accountStudentService;
    }
    @PostMapping("/accountstudent")
    public String addAccountStudent(Student student,
                                    Model model){
        accountStudentService.addStudentAccount(student);
        return "redirect:/students";
    }

    @GetMapping("/deleteaccountstudent/{account}")
    public String deleteAccountStudent(@PathVariable String account, Model model){
        System.out.println(account);
        accountStudentService.deleteStudentAccount(account);
        return "redirect:/students";
    }
}
